home *** CD-ROM | disk | FTP | other *** search
/ MacWorld: Complete Mac Interactive / Macworld Complete Mac Interactive CD)(1994).iso / The Best of BMUG / Utilities / Text and Speech / Alpha.5.76 / Tcl / SystemCode / menus.tcl < prev    next >
Text File  |  1994-03-15  |  7KB  |  411 lines

  1. # A few useful routines.
  2.  
  3. proc makeMenuPermanent {menu} {
  4.     global permanentMenus
  5.     
  6.     set permanentMenus($menu) 1
  7. }
  8.  
  9. if {[catch {set renamedRemove}]} {
  10.     rename removeMenu oldRemoveMenu
  11.     set renamedRemove 1
  12. }
  13.  
  14. proc removeMenu {name} {
  15.     global    permanentMenus
  16.     
  17.     if {![catch {set permanentMenus($name)}]} return
  18.     oldRemoveMenu $name
  19. }
  20.  
  21.  
  22. # My menus.        
  23.  
  24. menu -n File -p fileMenuProc {
  25.     "/Nnew"
  26.     "/Oopen…"
  27.     "/Wclose"
  28.     {menu -n fileSets {
  29.         {menu -n choose -p changeFileSet {}}
  30.         {menu -n files {}}
  31.         "createFileset…"
  32.         "dumpFileset…"
  33.         "(-"
  34.         "findTag"
  35.         "createTagFile"}}
  36.     "(-"
  37.     "/Ssave"
  38.     "saveAs…"
  39.     "revert"
  40.     "(-"
  41.     "/Yshell"
  42.     "(-"
  43.     "pageSetup…"
  44.     "/Pprint…"
  45.     "(-"
  46.     "/Qquit"
  47. }
  48.  
  49. proc fileMenuProc {menu item} {
  50.     if {$item == "open"} {
  51.         findFile
  52.     } elseif {$item == "close"} {
  53.         killWindow
  54.     } else {
  55.         $item
  56.     }
  57. }
  58.  
  59.  
  60. menu -n Edit {
  61.     "/Zundo"
  62.     "/Dredo"
  63.     "/Lload"
  64.     "(-"
  65.     "/Xcut"
  66.     "/Ccopy"
  67.     "/Vpaste"
  68.     "(-"
  69.     "/.pastePop"
  70.     "yank"
  71.     "/AselectAll"
  72.     "clear"
  73.     "(-"
  74.     {/[shiftLeft}
  75.     {/]shiftRight}
  76.     "/Bbalance"
  77. }
  78.  
  79.  
  80. menu -n Search {
  81.     "/Ffind…"
  82.     "/GrepeatSearchForward"
  83.     "/IrepeatSearchBackward"
  84.     "/TfindInNextFile"
  85.     "(-"
  86.     "/EenterSelection"
  87.     "(-"
  88.     "/Ureplace"
  89.     "/Hreplace&FindAgain"
  90.     "replaceAll"
  91.     "(-"
  92.     "/ gotoLine"
  93.     {menu -n namedMarks -p namedMarkProc {
  94.         "set…"
  95.         "goto…"
  96.         "remove…"}}
  97.     {menu -n unnamedMarks -p unnamedMarkproc {
  98.         "set…"
  99.         "exchangePointAndMark"
  100.         "/=hilite"}}
  101.     {menu -n markStack -p markMenuProc { "push" "pop"}}
  102. }
  103.  
  104. proc namedMarkProc {menu item} {
  105.     switch $item {
  106.         "set"         {setNamedMark}
  107.         "goto"        {gotoNamedMark}
  108.         "remove"    {removeNamedMark}
  109.     }
  110. }
  111.  
  112. proc unnamedMarkproc {menu item} {
  113.     switch $item {
  114.         "set"                     {setMark}
  115.         "exchangePointAndMark"    {exchangePointAndMark}
  116.         "hilite"                {markHilite}
  117.     }
  118. }
  119.     
  120. proc markMenuProc {menu item} {
  121.     switch $item {
  122.         "push"     {pushMark}
  123.         "pop"    {popMark}
  124.     }
  125. }
  126.         
  127.     
  128. menu    -n Utilities {
  129.         "longMenus"
  130.         {menu -n fileUtils {
  131.             "insertFile…"
  132.             "(-"
  133.             "fileRemove…"
  134.             "fileInfo/=…"}}
  135.         {menu -n Clips {
  136.             "copyNamedClipboard…"
  137.             "cutNamedClipboard…"
  138.             "pasteNamedClipboard…"}}
  139.         "(-"
  140.         {menu -n arrange {
  141.             "vertically^1"
  142.             "horizontally^2"
  143.             "tiled^3"
  144.             "overlay^4"}}
  145.         "zoom//"}
  146.  
  147.  
  148. menu    -n "Utils" {
  149.         "shortMenus"
  150.         {menu -n Flags -p editFlag {}}
  151.         {menu -n Vars -p editVar {}}
  152.         {menu -n fileUtils {
  153.             "insertPathName…"
  154.             "insertFile…"
  155.             "fileRemove…"
  156.             "fileInfo…"
  157.             "wordCount"}}
  158.         "(-"
  159.         {menu -n Eval {
  160.             "evalCommand/\\"
  161.             "evalToText/'"
  162.             "execCommand"
  163.             "repeatEval"
  164.             "iterationCount"}}
  165.         {menu -n KbdMacros {
  166.             "startKeyboardMacro"
  167.             "endKeyboardMacro"
  168.             "executeKeyboardMacro"
  169.             "dumpMacro"}}
  170.         "(-"
  171.         "spellcheckWindow"
  172.         "selectParagraph"
  173.         {menu -n NamedClipboards -p namedClipMenuProc {"copy" "cut" "paste"}}
  174. }
  175.  
  176. proc namedClipMenuProc {menu item} {
  177.     switch $item {
  178.         "copy"         "copyNamedClipboard"
  179.         "cut"         "cutNamedClipboard"
  180.         "paste"     "pasteNamedClipboard"
  181.     }
  182. }
  183.  
  184.         
  185. menu    -n Mode {
  186.         "listBindings"
  187.         "describeBinding"
  188.         {menu -n asciiEtc {
  189.             "keyCode"
  190.             "keyAscii"
  191.             "getAscii"
  192.             "insertAscii"}}
  193.         "(-"
  194.         "setFontsTabs…"
  195.         {menu     -n Colors {
  196.             "foreColor"
  197.             "backColor"
  198.             "dumpColors"}}
  199.         "(-"
  200.         {menu -m -n switchTo -p switchProc {
  201.             "/`MacMiNT"
  202.             "THINK Project Manager"
  203.             "MPW Shell"
  204.             "Versaterm PRO"
  205.             "MacLayers"}}
  206.         "toolserverShell"
  207.         "(-"
  208.         "loadElectricAlias"
  209. }
  210.  
  211. # ==== NOTE:  rectMarkHilite, onespace, centerRedraw, doTab
  212. menu    -n Convert {
  213.         "fillRegion"
  214.         "fillParagraph"
  215.         "wrapRegion"
  216.         "wrapParagraph"
  217.         "joinRegion"
  218.         "sortLines"
  219.         "matchingLines"
  220.         "(-"
  221.         "zapInvisibles"
  222.         "tabsToSpaces"
  223.         "spacesToTabs"
  224.         "(-"
  225.         {menu    -n Strings {
  226.             "insertPrefix"
  227.             "insertSuffix"
  228.             "removePrefix"
  229.             "removeSuffix"
  230.             "setPrefix"
  231.             "setSuffix"}}
  232.         {menu    -n Comment {
  233.             "transposeChars"
  234.             "transposeWords"
  235.             "commentBox"
  236.             "uncommentBox"}}
  237.         "(-"
  238.         {menu    -n Filters {
  239.             "replaceInRegion"
  240.             "filterLines"
  241.             "filterParagraphs"
  242.             "sortParagraphs"
  243.             "fillRegionByPar"
  244.             "lineToParagraph"
  245.             "paragraphToLine"}}
  246.         "downcaseRegion"
  247.         "upcaseRegion"
  248. }
  249.  
  250. # Real Kludge
  251. proc helpMenuProc {menu item} {
  252.     global HOME helpMenu
  253.     
  254.     if {$menu == $helpMenu} {
  255.         edit -r -m $HOME:Help:$item
  256.     } else {
  257.         edit -r -m $HOME:Help:$menu:$item
  258.     }        
  259. }
  260.  
  261. proc strip {arg} {
  262.     if {[regsub -all {\\([][\{\}])} $arg {\1} v]} {return $v}
  263.     return $arg
  264. }
  265.  
  266.  
  267. # proc buildHelpMenu {f} {
  268. #     global helpArr helpMenu
  269. #     if {[file isfile $f]} { return [file tail $f] }
  270. #     
  271. #     set sub ""
  272. #     set subd ""
  273. #     foreach s [glob $f:*] {
  274. #         if {[string match "*~" $s]} continue
  275. #         set res [buildHelpMenu $s]
  276. #         if {[string match "menu*" $res]} {
  277. #             lappend subd $res
  278. #         } else {
  279. #             lappend sub $res
  280. #         }
  281. #     }
  282. #     set title [file tail $f]
  283. #     if {$title == "Help"} {set title $helpMenu}
  284. #     list menu -n $title -m -p "helpMenuProc" [concat $sub $subd]
  285. # }
  286. # catch {eval [buildHelpMenu $HOME:Help]}
  287.  
  288. menu -n $helpMenu -m -p helpMenuProc {
  289.     "Intro"
  290.     "(-"
  291.     "Alpha Commands"
  292.     "Tcl Commands"
  293.     "(-"
  294.     "Customizing"
  295.     "Debugging"
  296.     "Default Key Bindings"
  297.     "Default Key Bindings 2"
  298.     "electricAlias Help"
  299.     "LaTeX Help"
  300.     "Regular Expressions"
  301.     "Shells"
  302.     "Tcl Library - auto-loading"
  303.     "Tcl Mailing List"
  304.     "XTCLs"
  305. }
  306.  
  307.  
  308. proc switchProc {menu name} {
  309.     switchTo $name
  310. }
  311.         
  312.  
  313. proc colorMenuProc {menu item} {
  314.     if {$item == "removeColors"} {
  315.         removeColors
  316.         return
  317.     }
  318.     set one [getPos]
  319.     if {[set two [selEnd]] == $one} {
  320.         set two [getMark]
  321.         if {$two < $one} {
  322.             set temp $two
  323.             set two $one
  324.             set one $temp
  325.         }
  326.     }
  327.     colorize $one $two $item
  328. }
  329.  
  330. menu -n $winMenu -p menuWin {
  331.         {menu -n arrange {
  332.             "vertically^1"
  333.             "horizontally^2"
  334.             "tiled^3"
  335.             "overlay^4"}}
  336.         {menu -n colors -p colorMenuProc {
  337.             "black"
  338.             "blue"
  339.             "cyan"
  340.             "green"
  341.             "magenta"
  342.             "red"
  343.             "white"
  344.             "yellow"
  345.             "(-"
  346.             "removeColors"
  347.         }}            
  348.         "(-"
  349.         "//zoom"
  350.         "iconify"
  351.         "dispFullName"
  352.         "toggleScrollbar"
  353.         "(-"
  354.         "nextWindow"
  355.         "swapWithNext"
  356.         "/;chooseAWindow"
  357.         "prevWindow"
  358.         "closeAll"
  359.         "saveAll"
  360.         "(-"
  361. }
  362.  
  363.  
  364. # We may be reloading, so add whatever windows we have
  365. if {[info exists winNameToNum]} {
  366.     set nms [array names winNameToNum]
  367.     foreach name $nms {
  368.         if {$fullNames} {
  369.             set item $name
  370.         } else {
  371.             regexp {[^:]*$} $name item
  372.         }
  373.         set num $winNameToNum($name)
  374.         if {$num < 10}     {
  375.             addMenuItem -m Wins /$num$item
  376.         } else {
  377.             addMenuItem -m Wins $item
  378.         }
  379.     }
  380. }
  381.  
  382. insertMenu "File"
  383. insertMenu "Edit"
  384. insertMenu "Search"
  385. insertMenu "Utils"
  386. insertMenu "Mode"
  387. enableMenuItem NamedClipboards pasteNamedClipboard off
  388. insertMenu "Convert"
  389. insertMenu $winMenu
  390. catch {insertMenu $helpMenu}
  391.  
  392. proc shortMenus {} {
  393.     global winMenu
  394.     removeMenu "Utils"
  395.     removeMenu "Mode"
  396.     removeMenu "Convert"
  397.     removeMenu $winMenu
  398.     insertMenu "Utilities"
  399. }
  400.  
  401. proc longMenus {} {
  402.     global winMenu
  403.     removeMenu "Utilities"
  404.     insertMenu "Utils"
  405.     insertMenu "Mode"
  406.     insertMenu "Convert"
  407.     insertMenu $winMenu
  408. }
  409.  
  410.  
  411.